import { defineStore } from 'pinia';
import { Session } from '/@/utils/storage';
import { getDoctorInfo, getUserInfo, login, loginByMobile, loginBySocial, refreshTokenApi } from '/@/api/login/index';
import other from '/@/utils/other';
import { useMessage } from '/@/hooks/message';

/**
 * @function useDoctorInfo
 * @returns {DoctorBaseInfoState}
 */
export const useDoctorInfo = defineStore('doctorInfo', {
  state: (): DoctorBaseInfoState => ({
    doctorBaseInfo: {
      doctorUid: '',
      doctorName: '',
      doctorPhonenumber: '',
      position: '',
      affiliatedHospital: '',
      permission: '',
      department: '',
      username: '',
    },
  }),
  actions: {

    /**
     * 获取医生信息
     * @function setDoctorInfos
     * @async
     */
    async setDoctorInfos(userInfos: any) {
      // TODO: 需要考虑身份调用这个函数，部署后修改身份ID
      // 验证医生身份是否在this.userInfos.roles数组中，不在则不调用
      const doctorRole = ["1811326400899379201", "1811326467232296962"];
      if (userInfos.roles.some((role) => doctorRole.includes(role)))
      {
        // 配置doctor条件
        const doctor = {
          doctorPhonenumber: userInfos.user.phone,
        }

        await getDoctorInfo(doctor).then((res) => {
          this.doctorBaseInfo = res.data[0];
        });
      }
    },
  }
});